package com.jsy.mini12306.order.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;

import javax.annotation.Resource;

/**
 * @author: SongyangJi
 * @description:
 * @since: 2021/9/9
 */


@Configuration
public class MailConf {

    @Value("${spring.mail.username}")
    String username;

    @Resource
    private JavaMailSender mailSender;

    public void sendEmail(String toEmail,String subject,String message) {
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        // 邮件发送者，这里不能随便填写，必须是真实的发送邮件的邮箱名称
        mailMessage.setFrom(username);
        // 邮件接受者
        mailMessage.setTo(toEmail);
        // 邮件主题
        mailMessage.setSubject(subject);
        // 邮件内容
        mailMessage.setText(message);
        // 发送邮件
        mailSender.send(mailMessage);
    }



}